﻿using Microsoft.AspNetCore.Http;
using SXICE.Core.Domains;
using SXICE.Core.Helpers;
using SXICE.WebAPI.Models;

namespace SXICE.WebAPI.Utilities
{
    /// <summary>
    /// 工作上下文
    /// </summary>
    public class WorkContext
    {
        /// <summary>
        /// 客户
        /// </summary>
        public static CustomerClaimsPrincipal Customer
        {
            get
            {
                var httpContext = RuntimeHelper.Resolve<IHttpContextAccessor>();
                return httpContext.HttpContext.User.ToEntity<CustomerClaimsPrincipal>();
            }
        }

        /// <summary>
        /// 转换成客户
        /// </summary>
        public static Customer ToCustomer
        {
            get
            {
                var c = Customer;
                return new Customer
                {
                    Id = c.Id,
                    IDNumber = c.IDNumber,
                    Phone = c.Phone,
                    Name = c.Name
                };
            }
        }
    }
}
